package com.jstyle.jclife.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.demon.js_pdf.WebViewHelper;
import com.jstyle.jclife.R;

import java.io.File;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PdfPreviewActivity extends AppCompatActivity {
    public final static String PDF_PATH="PDF_PATH";
    @BindView(R.id.webView_pdf)
    WebView webViewPdf;
    private static final String TAG = "PdfPreviewActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pdf);
        ButterKnife.bind(this);
        String pdfUrl=getIntent().getStringExtra(PDF_PATH);
        if(TextUtils.isEmpty(pdfUrl))return;
        Log.i(TAG, "onCreate: "+pdfUrl);
        File file=new File(pdfUrl);
        if(!file.exists())return;
        WebSettings webSettings = webViewPdf.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setAllowFileAccess(true);
        webSettings.setAllowFileAccessFromFileURLs(true);
        webSettings.setAllowUniversalAccessFromFileURLs(true);
        webSettings.setSupportZoom(true);//缩放开关，设置此属性，仅支持双击缩放，不支持触摸缩放
        webSettings.setBuiltInZoomControls(true);  //设置是否可缩放，会出现缩放工具（若为true则上面的设值也默认为true）
        webSettings.setDisplayZoomControls(false);
        WebViewHelper.WebViewLoadPDF(webViewPdf, pdfUrl);
     //   webViewPdf.loadUrl("file:///android_asset/index.html?" + pdfUrl);
    }
}
